﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class admin_student : System.Web.UI.Page
{
    protected Administrator admin;
    int guid;
    public Student stu;
    protected void Page_Load(object sender, EventArgs e)
    {
        admin = Administrator.Check();
        if (admin == null)
        {
            Session.Add(Params.SystemError, "请先登录");
            Response.Redirect(Params.RootHttp + "default.aspx");
        }
        this.guid = Convert.ToInt32(Request.Params["guid"]);
        this.stu = new Student(guid);
        if (!Page.IsPostBack)
        {
            this.MyDataBind();
        }
    }

    private void MyDataBind()
    {
        this.conNav.Title = "学生信息-" + this.stu.RealName;
        this.Title = "管理员-学生信息-" + this.stu.RealName;
        this.hlStudent.NavigateUrl = Params.StudentFolderHttp + "default.aspx?uid=" + Server.UrlEncode(stu.UserID);
        this.labID.Text = stu.UserID;
        this.labPaper.Text = stu.PaperName.Trim();
        this.tbEmail.Text = stu.Email;
        this.tbName.Text = stu.RealName;
        this.ddDoctor.DataSource = Doctor.Doctors(false);
        this.ddDoctor.DataBind();
        this.ddDoctor.SelectedValue = stu.DoctorGuid.ToString();
        this.ddExpert.DataSource = Doctor.Experts(true);
        this.ddExpert.DataBind();
        this.ddExpert.SelectedValue = stu.ExpertGuid.ToString();
        this.btnDelete.Attributes.Add("onclick", "return confirm('确定删除该学生以及所有相关数据？')");
        this.btnResetPwd.Attributes.Add("onclick", "return confirm('确定重置密码为学生的ID？')");

    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        string n = this.tbName.Text.Trim();
        string email = this.tbEmail.Text.Trim();
        int dg = Convert.ToInt32(this.ddDoctor.SelectedValue);
        int eg = Convert.ToInt32(this.ddExpert.SelectedValue);
        if (n == "")
        {
            this.info.SetMessage("姓名不能为空！");
            return;
        }
        stu.RealName = n;
        stu.Email = email;
        stu.DoctorGuid = dg;
        stu.ExpertGuid = eg;
        stu.Update();
        Session.Add(Params.SystemError, "修改成功");
        Response.Redirect(Request.RawUrl);
    }
    protected void btnResetPwd_Click(object sender, EventArgs e)
    {
        this.stu.Password = this.stu.UserID;
        this.stu.Update();
        this.info.SetMessage("重置成功");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        Student.Delete(this.guid);
        Session.Add(Params.SystemError, "删除成功");
        Response.Redirect(Params.AdminFolderHttp+"students.aspx");
    }
}
